package com.sai.jsai.common.starter.web.configuration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jisai
 * @version 0.0.1
 * @Description Swagger 配置
 * @createTime 2024/10/27
 */
@Configuration
@EnableConfigurationProperties(SwaggerProperties.class)
public class SwaggerConfiguration {

    @Bean
    public OpenAPI createApi(SwaggerProperties properties) {
        // 接口信息
        return new OpenAPI()
                // 接口信息
                .info(buildInfo(properties));
    }

    private Info buildInfo(SwaggerProperties properties) {
        return new Info()
                // 标题
                .title(properties.getTitle())
                // 版本
                .version(properties.getVersion())
                // 描述
                .description(properties.getDescription())
                // 作者信息
                .contact(new Contact().name(properties.getAuthor()));
    }

}
